<!DOCTYPE HTML>
<html style="background: #f9f9f9">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>法援宝</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>
</head>
<body>
<div id="secHeader">
  <header class="header">
      <a href="javascript:void(0);" onclick="api.closeWin()" class="back_btn"><img src="../image/head-fanhui.png" alt=""></a>
      <h2>合同文书</h2>
      <a href="javascript:void (0);" class="kinds_btn">分类</a>
  </header>
</div>

<section class="contract_section">
    <div class="contract_search">
        <form action="" onsubmit="return false;"><input type="text" placeholder="搜索合同文书" id="key"></form>
        <span id="total">共有0份合同可下载</span>
    </div>
    <div class="contract_list">
        <ul id='con'>



        </ul>
    </div>
</section>
<section class="fixed_bg">
    <div class="contract_kinds">
        <div class="news_title">
            <h2>合同分类</h2>
        </div>
        <div class="kinds_list">
            <ul id='cate'>

            </ul>
        </div>
        <div class="contract_btn">
            <a href="javascript:void (0);" class="cancel_btn" onclick="shou()">取消</a>
            <a href="javascript:void (0);" class="sure_btn" onclick="changetype()">确定</a>
        </div>
    </div>
</section>


</body>

<script>
    var page=0;
    var p='';
    var type=0;
    var name=''

    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });
        
        api.addEventListener({name:'scrolltobottom'}, function(ret, err){

            toDoRequest();

        });

         p={model:'hetong'};
        api.ajax({
            url: webSiteUrl+'/app/home/count',
            method: 'post',
            data: {
                values:p
            }
        }, function(ret, err) {
            api.hideProgress();
            if(ret.code==200){

                $('#total').html('共有'+ret.data+'份合同可下载');

            }
            cate()
        });

        //下拉刷新
        api.setRefreshHeaderInfo({
          visible: true,
          bgColor: 'rgba(255,255,255,255)',
          textColor: '#666',
          textDown: '下拉刷新',
          textUp: '释放刷新'
        }, function(ret, err) {
          toDoRefresh();
        });

        para=api.pageParam;

       // cate()
    };

    function toDoRequest(){
        name=$('#key').val();
        page++;
      //  alert(type+','+page+','+name);
        p= {model:'hetong',type:type,page:page,pagesize:6,name:name};
        //alert(JSON.stringify(p));
        api.ajax({
            url: webSiteUrl+'/app/home/lists',
            method: 'post',
            data: {
                values: p
            }
        }, function(ret, err) {
            api.hideProgress();

            if(ret.code==200){

                html = "";
                var tj=ret.data;

                if(tj != null){

for(var i=0;i<tj.length;i++){
html+='<li onclick="hetongdetail('+tj[i].id+')"><img src="'+webSiteUrl+tj[i].icon+'" alt=""><div class="info"><h6>'+tj[i].name+'</h6><span>￥'+tj[i].money+'</span></div></li>';
}
                }
                if(page==1){
                    $('#con').html(html);
                }else{
                    $('#con').append(html);
                }
                


            }else{
                if(page==1){
                    $('#con').html('<p style="text-align:center">暂无数据</p>');
                }

            }
        });

    }
    function cate(){
    // alert(11);
        var p={type:114};
        api.ajax({
            url: webSiteUrl+'/app/public/cate',
            method: 'post',
            data: {
                values:p
            }
        }, function(ret, err) {
            api.hideProgress();

            if(ret.code==200){

                var tj=ret.data;
                html = "";
                for(var i=0;i<tj.length;i++){
                    if(i==0){
                        html+='<li class="active" data="'+tj[i].id+'" style="cursor:pointer">'+tj[i].title+'</li>';
                    }else{
                        html+='<li  data="'+tj[i].id+'" style="cursor:pointer">'+tj[i].title+'</li>';
                    }


                }
                $('#cate').html(html);

                toDoRequest()
            }
        });

    }
    function changetype(){
        shou();
        var id= $(".kinds_list ul").find('.active').attr('data');
        page=0
        type=id
        toDoRequest()

    }
    $('form').on('submit', function(e){
        name=$('#key').val();
        page=0
        toDoRequest()
    });

    //合同搜索
    $(".contract_search input").focus(function () {
        $('.contract_search span').hide()
    });
    $(".contract_search input").blur(function () {
        if($(this).val() ==''){
            $('.contract_search span').show()
        }else {
            $('.contract_search span').hide()
        }
    });

    $(".kinds_btn").click(function () {
        $(".fixed_bg").fadeToggle();
        $(".fixed_bg .contract_kinds").animate({
            'right': '0',
            'opacity': '1'
        },400);
    });
    function shou(){
        $(".fixed_bg").fadeToggle();
        $(".fixed_bg .contract_kinds").animate({
            'right': '-6rem',
            'opacity': '0'
        },400);
    }


    //合同条件搜索
    $(document).on('click',".kinds_list ul li",function(){
        $(this).addClass('active').siblings().removeClass('active');return;

    })

</script>
</html>
